<template>
  <div class="login-all">
    <h3>登录</h3>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item prop="adminName" label="账户名：">
        <el-input v-model="ruleForm.adminName" placeholder="请输入账户名"></el-input>
      </el-form-item>
      <el-form-item prop="password" label="密码：">
        <el-input v-model="ruleForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login_Allright">登录</el-button>
        <el-button @click="forgetPwd">忘记密码</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
  "admins"
);
export default {
  computed: {
    ...mapState(["ruleForm", "rules"]),
  },
  methods: {
    ...mapMutations(["handleClick", "forgetPwd"]),
    ...mapActions(["login"]),
    async login_Allright() {
      const data = await this.login();
      if (data.status) {
        localStorage.token = data.token;
        localStorage.state = data.data[0].power
        this.$router.push({
          name: "System",
          query: {
            power:data.data[0].power
          },
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./login.scss";
</style>